package com.ky.course.controller;

import com.ky.common.config.SystemConfig;
import com.ky.common.vo.R;
import com.ky.course.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * 粉丝关注表 前端控制器
 * </p>
 *
 * @author zpa
 * @since 2024-06-22
 */
@RestController
@RequestMapping("/course/follow")
public class FollowController {

    @Autowired
    private FollowService followService;


    /**
     * 关注功能
     *
     * @param request
     * @param followingId
     * @return
     */
    @GetMapping("/followUser")
    public R followUser(HttpServletRequest request, @RequestParam("followingId") Integer followingId) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        if (token == null) {
            return R.fail("您尚未登录");
        }
        if (followingId == null) {
            return R.fail("userId参数不能为空");
        }

        return followService.followUser(token, followingId);
    }


    /**
     * 取消关注用户
     *
     * @param request
     * @param followingId
     * @return
     */
    @GetMapping("/unfollowUser")
    public R unfollowUser(HttpServletRequest request, @RequestParam("followingId") Integer followingId) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        if (token == null) {
            return R.fail("您尚未登录");
        }
        if (followingId == null) {
            return R.fail("followingId参数不能为空");
        }
        return followService.unfollowUser(token, followingId);
    }

    @GetMapping("/unfollowTeacher")
    public R unfollowTeacher(HttpServletRequest request, @RequestParam("followingId") Integer followingId) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        if (token == null) {
            return R.fail("您尚未登录");
        }
        if (followingId == null) {
            return R.fail("followingId参数不能为空");
        }
        return followService.unfollowTeacher(token, followingId);
    }


    @GetMapping("/followTeacher")
    public R followTeacher(HttpServletRequest request, @RequestParam("followingId") Integer followingId) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        if (token == null) {
            return R.fail("您尚未登录");
        }
        if (followingId == null) {
            return R.fail("followingId参数不能为空");
        }
        return followService.followTeacher(token, followingId);
    }

    @GetMapping("/followArticle")
    public R followArticle(HttpServletRequest request, @RequestParam("followingId") Integer followingId) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        if (token == null) {
            return R.fail("您尚未登录");
        }
        if (followingId == null) {
            return R.fail("followingId参数不能为空");
        }
        return followService.followArticle(token,followingId);
    }


    @GetMapping("/unfollowArticle")
    public R unfollowArticle(HttpServletRequest request, @RequestParam("followingId") Integer followingId) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        if (token == null) {
            return R.fail("您尚未登录");
        }
        if (followingId == null) {
            return R.fail("followingId参数不能为空");
        }
        return followService.unfollowArticle(token, followingId);
    }


}

